package entity_beans;

import java.io.Serializable;
import java.util.List;
import java.util.Vector;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 * Klasa predstavlja Air_Transport putnika.
 * 
 * @author Uros Krkic
 */
@Entity
@Table(name = "passenger")
@NamedQueries(
	{
		@NamedQuery(name = "all_passengers", query = "select p from Passenger p"),
		@NamedQuery(name = "passenger_by_jmbg", query = "select p from Passenger p where p.jmbg = :jmbg")
	}
)
public class Passenger implements Serializable {

	private static final long serialVersionUID = -4560250926426461570L;

	@Id
	@Column(name = "jmbg")
	private Long jmbg;
	
	private String name;
	
	private String surname;
	
	
//	@ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy = "passengers")
	@ManyToMany(cascade = {}, fetch = FetchType.EAGER/*, mappedBy = "passengers"*/)
	private List<Flight> flights;
	
	
	
	public Long getJmbg() {
		return jmbg;
	}


	public void setJmbg(Long jmbg) {
		this.jmbg = jmbg;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getSurname() {
		return surname;
	}


	public void setSurname(String surname) {
		this.surname = surname;
	}


	public Passenger() {}
	
	
	public Passenger(long jmbg, String name, String surname) {
		flights = new Vector<Flight>();
		this.jmbg = jmbg;
		this.name = name;
		this.surname = surname;
	}
	
	
	@Override
	public String toString() {
		return name + " " + surname;
	}


	public List<Flight> getFlights() {
		return flights;
	}


	public void setFlights(List<Flight> flights) {
		this.flights = flights;
	}
	
	
	public void addToFlight(Flight flight) {
		this.flights.add(flight);
	}
	
}
